#include "OthelloAIGreedy.h"
#include "../framework/ChessBoard.h"
#include "../framework/GameRule.h"
#include "../framework/Player.h"
#include "OthelloGameRule.h"
#include <vector>
#include <cstdio>
#include <Windows.h>
#include <iostream>

OthelloAIGreedy::OthelloAIGreedy()
{
}
void OthelloAIGreedy::doChess(ChessBoard * chessBoard, GameRule * gameRule, Player * player){
    int x,y,xMax,yMax,xBest=0,yBest=0,tmp=0,eatNumBest=0;
    std::vector< std::vector<Chess*> >* chessBoardArray;
    std::vector<QPoint>* qPointList = new std::vector<QPoint>;
    chessBoardArray = chessBoard->getChessBoardInstance();
    xMax = chessBoard->getChessBoardLength();
    yMax = chessBoard->getChessBoardWidth();

    for(x=0;x<xMax;x++){
        for(y=0;y<yMax;y++){
            if((*chessBoardArray)[x][y]==NULL){
                tmp = ((OthelloGameRule*)gameRule)->eatNum(QPoint(x,y),player);
                if(tmp>eatNumBest){
                    eatNumBest = tmp;
                    xBest = x;
                    yBest = y;
                }
            }
        }
    }

    std::cout<<eatNumBest<<std::endl;

    qPointList->push_back(QPoint(xBest,yBest));
    Sleep(300);
    gameRule->putChess(qPointList,player);
    return;
}
